package com.abvnet.project.water.project.service;

import com.abvnet.common.utils.StringUtils;
import com.abvnet.common.utils.security.ShiroUtils;
import com.abvnet.common.utils.text.Convert;
import com.abvnet.project.water.project.domain.ProjectCustomerTrack;
import com.abvnet.project.water.project.mapper.ProjectCustomerTrackMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 客户跟踪 服务层实现
 * 
 * @author duj
 * @date 2019-08-17
 */
@Service
public class ProjectCustomerTrackServiceImpl implements IProjectCustomerTrackService {
	@Autowired
	private ProjectCustomerTrackMapper projectCustomerTrackMapper;

	/**
     * 查询客户跟踪信息
     * 
     * @param trackId 客户跟踪ID
     * @return 客户跟踪信息
     */
    @Override
	public ProjectCustomerTrack selectProjectCustomerTrackById(Long trackId) {
	    return projectCustomerTrackMapper.selectProjectCustomerTrackById(trackId);
	}
	
	/**
     * 查询客户跟踪列表
     * 
     * @param projectCustomerTrack 客户跟踪信息
     * @return 客户跟踪集合
     */
	@Override
	public List<ProjectCustomerTrack> selectProjectCustomerTrackList(ProjectCustomerTrack projectCustomerTrack) {
	    return projectCustomerTrackMapper.selectProjectCustomerTrackList(projectCustomerTrack);
	}

    @Override
    public List<ProjectCustomerTrack> selectProjectCustomerTrackListForApi(ProjectCustomerTrack projectCustomerTrack) {
        return projectCustomerTrackMapper.selectProjectCustomerTrackListForApi(projectCustomerTrack);
    }

    /**
     * 新增客户跟踪
     * 
     * @param projectCustomerTrack 客户跟踪信息
     * @return 结果
     */
	@Override
	public int insertProjectCustomerTrack(ProjectCustomerTrack projectCustomerTrack) {
	    if (StringUtils.isEmpty(projectCustomerTrack.getApiMode())) {
            projectCustomerTrack.setUserId(ShiroUtils.getUserId());
            projectCustomerTrack.setUserName(ShiroUtils.getSysUser().getUserName());
            projectCustomerTrack.setCreateBy(ShiroUtils.getLoginName());
        }
	    return projectCustomerTrackMapper.insertProjectCustomerTrack(projectCustomerTrack);
	}
	
	/**
     * 修改客户跟踪
     * 
     * @param projectCustomerTrack 客户跟踪信息
     * @return 结果
     */
	@Override
	public int updateProjectCustomerTrack(ProjectCustomerTrack projectCustomerTrack) {
        if (StringUtils.isEmpty(projectCustomerTrack.getApiMode())) {
            projectCustomerTrack.setUpdateBy(ShiroUtils.getLoginName());
        }
	    return projectCustomerTrackMapper.updateProjectCustomerTrack(projectCustomerTrack);
	}

	/**
     * 删除客户跟踪对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteProjectCustomerTrackByIds(String ids) {
		return projectCustomerTrackMapper.deleteProjectCustomerTrackByIds(Convert.toStrArray(ids));
	}
	
}